/*
 * @Descripttion: 
 * @version: 
 * @Author: xyh
 * @Date: 2021-03-29 10:58:34
 * @LastEditTime: 2021-04-01 15:16:29
 */

import {getHomeBanner} from '../api/url';
function asyncInit() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(100);
        }, 1000);
    });
}
async function  getBanner(){
    return getHomeBanner().then(res=>{
        if(res.code === 200){
            return res.rows
        }
    })
}
export default {
    namespace: "system", // 可省略
    state: {
        dataList : [],
        count : 1,
    },
 
    effects: {
        // generactor 这玩意还再用，我也是醉了
        //这个执行异步操作，这玩意是* 生成器函数？？
        * getBannerAction(action, { call, put }) {
            let data = yield call(getBanner);
            console.log('banner',data);
            yield put({ type: "setDataList", payload:data });
        }
 
    },
    reducers: {
        addCount(state, {payload}) {
            console.log('state',state);
            console.log('payload',payload);
            return {
                ...state,count:payload
            }
        },
        setDataList(state, {payload}){
            console.log('setDatalist state',state);
            console.log('setDatalist payload',payload);

            // return [...state,payload]
            return {
                ...state,dataList:payload
            }
        },
 
    }
}
